/* 
 * File:   main.cpp
 * Author: Michael
 *
 * Created on September 25, 2010, 7:24 PM
 */

#include <cstdlib>
#include <iostream>
#include <string>

#include "map.h"

using namespace std;

static bool checkArgs(int argc, char** argv);
//EFFECTS: handles command line arguments
//         returns true if --Stack was selected


int main(int argc, char** argv) {
    bool DEBUG = false;

    bool useStack = checkArgs(argc, argv);
    string input = "";
        if(!getline(cin, input)){ cerr << "EoF!"; cerr.flush(); exit(1);}
    int rooms = atoi(input.c_str());
        if (rooms <= 0){
            cerr << "Error in reading number of rooms!\n";
            cerr.flush();
            exit(1);
        }

    string output = "";
    for(int i = 0; i < rooms; i++){
        map m(useStack, i==rooms-1 , DEBUG);
        if(m.getSolution()=="@"){
            cout << "Escape failed.\n";
            cout.flush();
            exit(0);
        }
        output = output + m.getSolution();
    }

    cout << output;
    cout.flush();
    return (EXIT_SUCCESS);
}

static bool checkArgs(int argc, char** argv){
    if(argc != 2){
        cerr << "Too many arguments!\n";
        cerr.flush();
        exit(1);
    }

    if(strcmp(argv[1], "--Stack")==0){
            return true;
    } else if(strcmp(argv[1], "--Queue")==0){
            return false;
    } else {
        cerr << "Improper arguments!\n";
        cerr.flush();
        exit(1);
    }
}

